package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import selenium.WebDriverWrapper;
import java.util.concurrent.TimeUnit;

public class SearchPage extends BasePage {
    private static final By SEARCH_LOCATOR = By.xpath("//input[contains(@class,'header-search-input-text')]");
    private static final By PRODUCT_NAME_LOCATOR = By.xpath("//div[@class='search-result']/div[@class='container']/div[@class='search-result-goods']/div[@class='g-i-list available clearfix']/div[@class='g-i-list-right-part']/div[@class='g-i-list-title']/a");
    private static final By COMPARISON_SELECTION_LOCATOR = By.xpath("//div[@class='search-result']/div[@class='container']/div[@class='search-result-goods']/div[@class='g-i-list available clearfix']/div[@class='g-i-list-left-part']/div[@class='g-i-list-compare']/a");
    private String productName;

    public SearchPage(WebDriverWrapper driver){
        super (driver);
        URL = "http://rozetka.com.ua/search/";
        driver.get(URL);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    }

    public String searchProduct(String search){
        driver.findElement(SEARCH_LOCATOR).click();
        driver.findElement(SEARCH_LOCATOR).sendKeys(search + Keys.ENTER);
        productName = driver.findElement(PRODUCT_NAME_LOCATOR).getText();
        return productName;
    }

    public void addToComparison(){
        driver.findElement(COMPARISON_SELECTION_LOCATOR).click();
    }

    public void clearSearch(){
     driver.findElement(SEARCH_LOCATOR).click();
     driver.findElement(SEARCH_LOCATOR).sendKeys(Keys.chord(Keys.SHIFT,Keys.END,Keys.DELETE));
    }
}
